package com.xuecheng.order.controller;

import com.xuecheng.commons.model.dto.MyOrderDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.order.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.FileNotFoundException;

/**
 * <p>
 * 订单前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService  ordersService;

    /**
     * 创建订单请求
     * @param coursePubId 课程发布id
     * @return 订单id
     */
    @PostMapping("/create/{coursePubId}")
    public ResponseResult<String> createOrder(@PathVariable("coursePubId") Long coursePubId){
        return ordersService.createOrder(coursePubId);
    }

    /**
     * 查询订单的支付状态
     * @param orderNo 订单号
     * @return OrdersVo
     */
    @GetMapping("/{orderNo}")
    public ResponseResult queryOrders(@PathVariable("orderNo") String orderNo){
        return ordersService.queryOrders(orderNo);
    }

    /**
     * 查询用户的订单
     * @param pageRequest 分页参数
     * @param dto MyOrderDto
     * @return MyOrderVo
     */
    @PostMapping("/my-list")
    public ResponseResult myOrdersList(PageRequest pageRequest,@RequestBody MyOrderDto dto){
        return ordersService.myOrdersList(pageRequest,dto);
    }

    /**
     * 订单查询
     * @param pageRequest 分页
     * @param dto dto
     * @return
     */
    @PostMapping("/org-list")
    public ResponseResult countOrders(PageRequest pageRequest,@RequestBody MyOrderDto dto){
        return ordersService.countOrders(pageRequest,dto);
    }
    /**
     * 订单excel生成
     */
    @GetMapping("/order/excel")
    public ResponseResult ordersExcel(Long companyId) throws FileNotFoundException {
        return ordersService.ordersExcel(companyId);
    }
}
